package com.weijin.service.RedisService;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.weijin.vo.RestResultVo;
import com.weijin.web.websocket.ChatAnnoHandler;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Set;

/**
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/21 10:09
 */
@Component
@Slf4j
public class MessageBroadcaster {
    public static final String CHANEL = "chat:chanel";

    @Resource
    private RedisTemplate<String, Objects> redisTemplate;

    /**
     * 发送消息到频道
     *
     * @param message 消息
     */
    public void broadcast(String message) {
        redisTemplate.convertAndSend(CHANEL, message);
    }


}
